Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tests for Gatsbygram #4790

Merged
merged 9 commits into from
Apr 14, 2018
Merged

Conversation

tsriram
Copy link
Contributor

@tsriram tsriram commented Apr 1, 2018

First things first, here's a video:

gatsbygram

Taking #4361 forward, I've written UI tests of the example site Gatsbygram using Cypress. This is my first time writing tests using Cypress so it's quite possible that I'm not doing things in the best possible way 😄

Though I think there are enough tests to know whether Gatsbygram is working, this is still a WIP PR as we'd need to set up CI to run UI tests along with other tests - wonder if we need to run these tests for all PRs? Would love to get some feedback from people who've worked with Cypress.

TODO:

  • Remove data-test* attributes from production builds
  • Set up CI to run these tests

@ghost ghost assigned tsriram Apr 1, 2018
@ghost ghost added the review label Apr 1, 2018
@gatsbybot
Copy link
Collaborator

gatsbybot commented Apr 1, 2018

Deploy preview for using-drupal ready!

Built with commit 6748a67

https://deploy-preview-4790--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Apr 1, 2018

Deploy preview for gatsbygram ready!

Built with commit 5804008766922406f0a3990821e7f3d18c507e4e

https://deploy-preview-4790--gatsbygram.netlify.com

@tsriram
Copy link
Contributor Author

tsriram commented Apr 3, 2018

Looks like we'll need a Gatsby plugin which uses babel-plugin-react-remove-properties
to remove the data-testid properties used for UI testing.

@KyleAMathews - would you prefer this to live in this repo as an official plugin or keep it outside?

@KyleAMathews
Copy link
Contributor

Oh nice! Yeah, it'd be great to have some UI tests run alongside the other tests. This is something that we're sorely missing atm because we could accidentally break Gatsby's runtime (happened a few times...) and not see it until it's deployed.

@KyleAMathews
Copy link
Contributor

I don't think the test properties matter much so let's not worry about removing them for the production build.

@tsriram
Copy link
Contributor Author

tsriram commented Apr 5, 2018

@KyleAMathews I've updated the Travis config to run UI tests as well and set Cypress to record video of tests that can viewed later on Cypress Dashboard (have added you to the gatsbyjs org there, check your email). For the video recording to work, we need an environment variable CYPRESS_RECORD_KEY set in Travis. I did it but the tests don't seem to find it and hence failing. I'm not sure if I have access to set the variable. Could you check if this env variable is set in Travis?

Value for this variable is available here - https://dashboard.cypress.io/#/projects/c9d3r3/settings

@@ -27,6 +27,23 @@ jobs:
script:
- yarn test

- stage: gatsbygram ui tests
language: node_js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsriram Can you add the env var here (maybe you tried that already)? Travis might not pick it up until this branch is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-allanson Ah, didn't know that ENV variables are not accessible before merging. Nope, I didn't try adding the variable here. Adding it here will make it public right? I'm not sure if it's okay. From Cypress docs:

If you have a public project you should still keep your record key secret. If someone knows both your record key and your projectId, they could record test runs for your project - which would mix up all of your results!

Wonder if it's okay for us to make it public? If yes, we can just pass the key from the npm script itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't know that ENV variables are not accessible before merging.

Oh hrmm, it seems I was wrong about that, Travis will use the yaml file from the current branch: https://docs.travis-ci.com/user/customizing-the-build/#Building-Specific-Branches

Yeah adding it here will make it public, but you can use the Travis CLI to encrypt env vars. See an example here.

Although pay attention to their note:

Encryption and decryption keys are tied to the repository. If you fork a project and add it to Travis CI, it will not have access to the encrypted variables.

Otherwise you may spend a lot of time (like I did 😅) wondering why your env var isn't working. It may be easier to merge this branch as-is, and then create smaller PRs straight from this repo to tinker with the travis.yml config.

Alternatively @KyleAMathews could add the env var via the Travis site (as you mentioned originally) which would certainly be quicker :), but I think it's nicer to keep the Travis config under version control where possible.

Copy link
Contributor Author

@tsriram tsriram Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hrmm, it seems I was wrong about that, Travis will use the yaml file from the current branch

Probably not 😄 Looks like the environment variables defined in repository settings are not "automatically" available to forks: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings. I think even if @KyleAMathews adds the env variable, it's not going to work. So, as you said it's probably better to merge this and have a branch from this repo itself to get this working.

@tsriram tsriram changed the title [WIP] UI tests for Gatsbygram UI tests for Gatsbygram Apr 5, 2018
@m-allanson
Copy link
Contributor

@KyleAMathews I think this is ready to go in if all looks good to you. @tsriram will have a follow up PR to get the Travis config sorted.

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Travis is failing... Let's get that working again and then merge this in. @tsriram I've added a comment.

"deploy": "gatsby build --prefix-paths && gh-pages -d public"
"deploy": "gatsby build --prefix-paths && gh-pages -d public",
"cy:open": "cypress open",
"cy:run": "cypress run --record"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsriram If this --record key is removed, that should make the CI tests pass again?

Then --record can be added back in a follow-up PR, along with the env var.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense. Will remove --record for now 👍

@tsriram
Copy link
Contributor Author

tsriram commented Apr 13, 2018

@m-allanson Builds are passing now except the DCO check. I think I've signed the commit correctly (amended it), but not sure why it's failing. Am I missing something?

Edit: I missed signing off all commits in the PR and for some reason git rebase --signoff isn't working - it says unknown option signoff'`. Will figure it out and update the PR soon.

Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
* update all gatsby dependencies to latest tag

* run cypress tests on travis, hopefully

* well, try again to run ui tests on travis

* add cypress videos to gitignore

* uncomment original travis stages

* update cypress project id

Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for wrangling with the DCO signoff :)

@KyleAMathews KyleAMathews merged commit bed4184 into gatsbyjs:master Apr 14, 2018
@KyleAMathews
Copy link
Contributor

Excellent work! Really excited to have UI tests running now 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants